package com.ruoyi.tsjData.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.pad.ChartLineDTO;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.calculate.BezierCurveUtil;
import com.ruoyi.tsjData.domain.plat.DataTshjZhd;
import com.ruoyi.tsjData.mapper.DataTshjZhdMapper;
import com.ruoyi.tsjData.service.IDataTshjZhdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;


/**
 * 提升机-制动测试Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-10-25
 */
@Service
public class DataTshjZhdServiceImpl implements IDataTshjZhdService
{
    @Autowired(required = false)
    private DataTshjZhdMapper dataTshjZhdMapper;

    /**
     * 查询提升机-制动测试
     * 
     * @param zhdId 提升机-制动测试主键
     * @return 提升机-制动测试
     */
    @Override
    public DataTshjZhd selectDataTshjZhdByZhdId(Long zhdId)
    {
        return dataTshjZhdMapper.selectDataTshjZhdByZhdId(zhdId);
    }

    /**
     * 制动测试数据
     * @param dataTaskId
     * @return
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataTshjZhd>> selectZhd(Long dataTaskId) {
        List<DataTshjZhd> dataTshjZhdEntities = dataTshjZhdMapper.selectDataTshjZhdByDataTaskId(dataTaskId);
        if (dataTshjZhdEntities.size() != 0) {
            dataTshjZhdEntities.forEach(item -> {
                item.setZhdsdChartLineDTO(BezierCurveUtil.calPoints(item.getZhdsdList(),item.getCsfsh().equals("2") ? 0.2f : 0.1f, false));
            });
        }
        return new AsyncResult<>(dataTshjZhdEntities);
    }

    /**
     * 查询提升机-制动测试
     *
     * @param dataTaskId 提升机-制动测试任务id
     * @return 提升机-制动测试
     */
    @Override
    public List<DataTshjZhd> selectDataTshjZhdByDataTaskId(Long dataTaskId) {
        return dataTshjZhdMapper.selectDataTshjZhdByDataTaskId(dataTaskId);
    }

    /**
     * 查询提升机-制动测试列表
     * 
     * @param dataTshjZhd 提升机-制动测试
     * @return 提升机-制动测试
     */
    @Override
    public List<DataTshjZhd> selectDataTshjZhdList(DataTshjZhd dataTshjZhd)
    {
        return dataTshjZhdMapper.selectDataTshjZhdList(dataTshjZhd);
    }

    /**
     * 新增提升机-制动测试
     * 
     * @param dataTshjZhd 提升机-制动测试
     * @return 结果
     */
    @Override
    public int insertDataTshjZhd(DataTshjZhd dataTshjZhd)
    {
        dataTshjZhd.setCreateTime(DateUtils.getNowDate());
        return dataTshjZhdMapper.insertDataTshjZhd(dataTshjZhd);
    }

    /**
     * 批量新增制动数据
     * @param dataTshjZhds 提升机-制动测试
     * @return
     */
    @Override
    public int batchDataTshjZhd(List<DataTshjZhd> dataTshjZhds) {
        return dataTshjZhdMapper.batchDataTshjZhd(dataTshjZhds);
    }

    /**
     * 修改提升机-制动测试
     * 
     * @param dataTshjZhd 提升机-制动测试
     * @return 结果
     */
    @Override
    public int updateDataTshjZhd(DataTshjZhd dataTshjZhd)
    {
        dataTshjZhd.setUpdateTime(DateUtils.getNowDate());
        return dataTshjZhdMapper.updateDataTshjZhd(dataTshjZhd);
    }

    /**
     * 批量更新提升机-制动测试
     * @param dataTshjZhds 提升机-制动测试
     * @return
     */
    @Override
    public int updateBatchDataTshjZhd(List<DataTshjZhd> dataTshjZhds) {
        return dataTshjZhdMapper.updateBatchDataTshjZhd(dataTshjZhds);
    }

    /**
     * 变更制动测试数据状态
     * @param dataTaskIds 提升机-制动测试任务id
     * @return
     */
    @Override
    public int updateDataTshjZhdByDataTaskIds(Long[] dataTaskIds) {
        return dataTshjZhdMapper.updateDataTshjZhdByDataTaskIds(dataTaskIds);
    }

    /**
     * 变更制动测试状态
     * @param dataTaskId
     * @param zhdId
     * @return
     */
    @Override
    public int updateDataTshjZhdByZhId(Long dataTaskId, Long zhdId) {
        return dataTshjZhdMapper.updateDataTshjZhdByZhId(dataTaskId, zhdId);
    }

    /**
     * 批量删除提升机-制动测试
     * 
     * @param zhdIds 需要删除的提升机-制动测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjZhdByZhdIds(Long[] zhdIds)
    {
        return dataTshjZhdMapper.deleteDataTshjZhdByZhdIds(zhdIds);
    }

    /**
     * 删除提升机-制动测试信息
     * 
     * @param zhdId 提升机-制动测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjZhdByZhdId(Long zhdId)
    {
        return dataTshjZhdMapper.deleteDataTshjZhdByZhdId(zhdId);
    }

    /**
     * 根据调整点位生成新曲线图
     *
     * @param charts
     */
    @Override
    public ChartLineDTO modifyChart(String charts, String csfsh) {
        List<Float> chartList = Arrays.stream(charts.split(",")).map(s->Float.parseFloat(s.trim())).collect(Collectors.toList());
        return BezierCurveUtil.calPoints(chartList, csfsh.equals("2") ? 0.2f : 0.1f, false);
    }

}

